home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Belgian Amiga Club - ADF Collection
/
BS1 part 26.zip
/
BS1 part 26
/
C for beginners.adf
/
source
/
pixel.c
< prev
next >
Wrap
C/C++ Source or Header
|
1978-01-17
|
2KB
|
92 lines
/* pixel.c 25.4.6 */
/* From Amiga C for Beginners */
/* by Abacus */
#include <exec/types.h>
#include <intuition/intuition.h>
extern struct Window *OpenWindow(); /* Declaration */
extern long *OpenLibrary(); /* Hello Aztec-User! */
extern double sin();
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
#define INTUITION_REV 0
#define GRAPHICS_REV 0
/* Number of colors of Workbench */
#define WB_COLORS 4
struct NewWindow NewWindow =
{
10, 50, /* X and Y Position */
360, 120, /* Width, Height */
3, 2, /* Color Indexes */
NULL,
SMART_REFRESH | ACTIVATE | WINDOWDRAG | WINDOWDEPTH,
NULL,
NULL,
"This Line is changed!",
NULL,
NULL,
0, 0,
640, 200, /* PAL users - change 200 to 256 */
WBENCHSCREEN
};
main()
{
struct Window *Window;
register struct RastPort *r;
register int i, j, top, yoffset;
int i_to, j_to, color, colors[512];
double factor;
if((IntuitionBase = (struct IntuitionBase *)
OpenLibrary("intuition.library", INTUITION_REV))
== NULL)
exit(FALSE);
if((GfxBase = (struct GfxBase *)
OpenLibrary("graphics.library", GRAPHICS_REV) )
== NULL)
exit(FALSE);
if((Window = OpenWindow(&NewWindow)) == NULL)
exit (FALSE);
r = Window->RPort;
top = Window->Height / 4;
factor = 2 * 3.1415926 / Window->Width * 1.5;
/* 1.5 Sine Waves */
for(i = 2, i_to = Window->Width - 2; i < i_to; i++)
{
for(j = 0; j < top; j++) /* A vertical line */
{ /* Transfer to Array */
color = ReadPixel(r, i, j);
if(++color == WB_COLORS)
colors[j] = 0;
else
colors[j] = color;
/* increase color index by one */
}
for(j = 0,
yoffset = top + top * sin(factor * i) + 16;
j < top; j++)
if(colors[j]) /* If Pixel should be set */
{
SetAPen(r, colors[j]);
WritePixel(r, i, j + yoffset);
}
}
Delay(1500); /* Wait 1500 Ticks = 30 seconds */
CloseWindow(Window);
CloseLibrary(GfxBase);
CloseLibrary(IntuitionBase);
exit(TRUE);
}